﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Loong.Threading.Locks.Database;

namespace Loong.Threading.Locks
{
    public class ResourceLockMap : IEntityTypeConfiguration<ResourceLock>
    {
        public void Configure(EntityTypeBuilder<ResourceLock> entity)
        {
            entity.Property(e => e.Resource)
                .IsUnicode(false)
                .HasMaxLength(50)
                .IsRequired();

            entity.Property(e => e.ExpireTime)
                .HasColumnType("datetime");

            entity.Property(e => e.LockOwner)
                .IsUnicode(false)
                .HasMaxLength(50)
                .IsRequired();

            entity.HasIndex(e => e.Resource)
                .IsUnique()
                .HasName("IX_ResourceLock_Resource");

            entity.ToTable("ResourceLock");
        }
    }
}
